package com.kaiwukj.android.ufamily.mvp.ui.page.service.community;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityNewResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.service.ServiceContract;

import javax.inject.Inject;

public class CommunityNewsPresenter extends BasePresenter<ServiceContract.Model, ServiceContract.CommunityNewView> {

    @Inject
    public CommunityNewsPresenter(ServiceContract.Model model, ServiceContract.CommunityNewView view) {
        super(model, view);
    }

    public void fetchCommunityNews(int communityId) {
        mModel.fetchCommunityNewData(communityId)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<CommunityNewResult>>(mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<CommunityNewResult> result) {
                        mRootView.onFetchResult(result.getList());
                    }
                });
    }
}
